<?php

class Application_Model_TypeProduit {
	
	protected $nom_type;
	protected $id_type;
	
	//--setters et getters--
	public function getName()
	{
		return $this->nom_type;
	}

	public function setName($nom)
	{
		$this->nom_type = $nom;
	}

	public function getId()
	{
		return $this->id_type;
	}

	public function setId($id)
	{
		$this->id_type = $id;
	}
	//----------------------

	public function getById($id)
	{
		$db = new Application_Model_TypeProduitTable();
		$rows = $db->fetchAll($db->select()->where('id_type = ?',$id));
		if(count($rows)>0)
		{
			$this->setId($id);
			$this->setName($rows[0]['nom_type']);
		}
		else
		{
			throw new Zend_Exception('Impossible de trouver le type n°'.$id);
		}
		return $this;
	}
}
